package site.assad.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.assad.dao.UserDao;
import site.assad.domain.User;

import java.util.List;

/**
 * Author: Al-assad 余林颖
 * E-mail: yulinying_1994@outlook.com
 * Date: 2017/12/18 12:03
 * Description: User 登陆服务，提供登陆验证等服务
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    //根据id查询用户
    public User getUserById(final String userId){
        return userDao.getUserById(userId);
    }

    //注册User
    @Transactional
    public boolean registerUser(User user){
        if(userDao.findUserByName(user.getUserName()).getUserId() == 0){
            userDao.addUser(user);
            return true;
        }else{
            return false;
        }
    }

    //根据用户名查询用户
    public User getUserByName(final String userName){
        return userDao.findUserByName(userName);
    }

    //获取所有User
    public List<User> getAllUser(){
        return userDao.getAllUser();
    }

}
